package entity

import (
	"ginfwk/domain/model/vo"
	"ginfwk/infrastructure/do"
	"time"
)

type UserEntity struct {
	Id        uint64    `json:"id,omitempty"`
	Name      string    `json:"name,omitempty"`
	Age       uint8     `json:"age,omitempty"`
	Address   string    `json:"address"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (u *UserEntity) SetAddress(address vo.AddressVO) {
	u.Address = address.String()
}

func NewUserFromUserDO(userDO *do.UserDO) *UserEntity {
	var u = new(UserEntity)
	u.fromUserDO(userDO)
	return u
}

func (u *UserEntity) fromUserDO(userDO *do.UserDO) {
	u.Id = userDO.Id
	u.Name = userDO.Name
	u.Age = userDO.Age
	u.CreatedAt = userDO.CreatedAt
	u.UpdatedAt = userDO.UpdatedAt
}

func (u *UserEntity) toUserDO() *do.UserDO {
	return &do.UserDO{
		Id:        0,
		Name:      u.Name,
		Age:       u.Age,
		CreatedAt: u.CreatedAt,
		UpdatedAt: u.UpdatedAt,
		Deleted:   0,
	}
}
